/*
 * @Author: 林武
 * @Date: 2022-07-18 18:21:57
 * @LastEditors: 林武
 * @LastEditTime: 2022-09-02 17:03:26
 * @FilePath: \233_Demo\assets\Scripts\FMJava.ts
 * @Description: 
 * 
 * Copyright (c) 2022 by 林武, All Rights Reserved.
 */
export default class FMJava {
    //关闭的回调
    private static onClose: Function = null;
    //失败的回调
    private static onFailed: Function = null;

    public static InterstitialAdNowTime: number = 0;
    public static InterstitialAdstopTime: number = 0;

    private static IsLookVideo: Boolean = false;

    /**
     * 播放激励视频
     * @param onClose   播放完成回调
     * @param onFailed  播放失败的回调
     */
    public static showRewardedVideoAd(onClose: Function, onFailed: Function) {
        if (this.IsLookVideo) {
            return;
        }
        this.IsLookVideo = true;
        setTimeout(() => {
            this.IsLookVideo = false;
        }, 3000);
        this.onClose = onClose;
        this.onFailed = onFailed;
        console.log("js  播放激励视频");
        // console.log(this.onClose);

        jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "showRewardedVideoAd", "()V");
    }


    static time = false

    /**
     * 播放全屏视频
     * @param onClose   播放完成回调
     * @param onFailed  播放失败的回调
     */
    public static show_FullScreenVideo(onClose: Function, onFailed: Function) {
        if(FMJava.time) return
        this.onClose = onClose;
        this.onFailed = onFailed;
        FMJava.time = true
        setTimeout(() => {
            FMJava.time = false;
        }, 60000);
        console.log("js 播放全屏视频");
        jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "FullScreenVideoAd", "()V");
    }

    /**
     *  回调  激励视频播放成功
     */
    public static listener_Video_finish(name: string) {
        console.log(" 回调  激励视频播放成功");
        if (this.onClose) {
            this.onClose(true);
        }
    }

    /**
     *  回调  激励视频播放错误
     */
    public static listener_Video_Error(name: string) {
        console.log(" 回调  激励视频播放错误");
        if (this.onFailed) {
            this.onFailed();
        }
    }

    /**
     *  回调  激励视频关闭
     */
    public static listener_Video_Close(name: string) {
        console.log(" 回调  视频播放关闭");
        if (this.onClose) {
            this.onClose(false);
        }
    }
}
